#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e5 + 10, INF = 0x3f3f3f3f;

int n, q;
int f[N], cnt[N], val[N];

int find(int x)
{
    if (x != f[x]) f[x] = find(f[x]);
    return f[x];
}

void solve()
{
    cin >> n >> q;
    for (int i = 1;i <= n;i++) f[i] = i, cnt[i] = 0, val[i] = 0;

    int op, u, v;
    while (q--) {
        cin >> op;
        if (op == 1) {
            cin >> u >> v;
            int fu = find(u), fv = find(v);
            if (fu == fv) continue;
            f[fv] = fu;
            cnt[fu] += cnt[fv];
        } else if (op == 2) {
            cin >> v;
            int fv = find(v);
            if (val[v] == 0) {
                cnt[fv]++;
                val[v] = 1;
            } else {
                cnt[fv]--;
                val[v] = 0;
            }
        } else {
            cin >> v;
            int fv = find(v);
            puts(cnt[fv] != 0 ? "Yes" : "No");
        }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}